import EditModal from "@/components/common/EditModal";
import React, {useRef, forwardRef, useImperativeHandle} from "react";
import {Button, Flex} from "antd";

interface IProps {
    btn: React.ReactNode
    setSelectRecentlyUID: (selectRecentlyUID: string) => void
    delOk: () => void
}

interface IModelRef {
    showModal: () => void
    handleCancel: (cb?: () => void) => void
    handleOk: (cb?: () => void) => void
}

const RecentlyDelModal = forwardRef(({ btn, setSelectRecentlyUID, delOk }: IProps, ref) => {
    const recentlyModalRef = useRef(null)
    const showModal = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IModelRef).showModal()
        }
    }
    const handleCancel = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IModelRef).handleCancel()
            setSelectRecentlyUID('')
        }
    }
    const handleOk = () => {
        if (recentlyModalRef.current) {
            (recentlyModalRef.current as IModelRef).handleOk(() => {
                delOk()
            })
        }
    }
    useImperativeHandle(ref, () => ({ showModal, handleOk }))
    return (
        <EditModal ref={recentlyModalRef} title={'提醒'} btn={btn} footer={
            <Flex gap='middle' wrap justify='end'>
                <Button onClick={handleCancel}>取消</Button>
                <Button type='primary' onClick={handleOk}>确定</Button>
            </Flex>
        } content={<div style={{textAlign: 'center'}}>删除后不可恢复，您确定删除该文件？</div>}/>
    )
})

export default RecentlyDelModal